<?php
if (!defined('IN_ZWS')) exit();

class PublicAction extends Action {
	function _initialize() {
		global $userInfo, $adminUid;
		switch (strtolower(MODULE_NAME)) { // 根据当前页面高亮导航栏
			case 'b':
				$this -> assign('nowNav', 1);
				break;
			case 'v':
				$this -> assign('nowNav', 2);
				break;
			case 'e':
				$this -> assign('nowNav', 3);
				break;
			case 'i':
				$this -> assign('nowNav', 4);
				break;
			default:
				$this -> assign('nowNav', 0);
				break;
		}
		// 检查是否已经登录以及登录状态
		if (isEmpty($_SESSION['uid']) || isEmpty($_SESSION['ltime'])) $this -> error("请先登录", '/u/login');
		$info = D('InfoView');
		$userInfo = $info -> where("User.id=" . $_SESSION['uid']) -> find();
		$adminUid = explode(',', setting('admin_uid'));
		$userInfo['avatar'] = array(300 => parseAvatar($userInfo['avatar']), 100 => parseAvatar($userInfo['avatar'], 100), 50 => parseAvatar($userInfo['avatar'], 50));
		if (empty($userInfo) || empty($userInfo['username']) || $_SESSION['ltime'] < $userInfo['cptime']) {
			unset ($_SESSION ['uid'], $_SESSION ['username'], $_SESSION ['ltime']);
			session('[destroy]');
			session('[regenerate]');
			$this -> error("登录状态已失效", '/u/login');
		}
		$this -> assign('siteName', setting('siteName'));
		$this -> assign('siteSubName', setting('siteSubName'));
		$this -> assign('siteDesc', setting('siteDesc'));
		$this -> assign('userInfo', $userInfo);
	}
}
